<script>
// import { computed } from 'vue';
// eslint-disable-next-line no-unused-vars
import { useUserStore } from '@/store/modules/user';
// eslint-disable-next-line no-unused-vars
import { storeToRefs } from 'pinia';
import { useRouter } from 'vue-router';
export default {
  name:'AppNav',
  setup(){
    const userStore = useUserStore();
    const { profile } = storeToRefs(userStore)

    const router = useRouter()
    // 用户登出，清除信息并通过路由实例跳转
    const logout = () => {
      userStore.$patch(state=>{
        state.profile.token = false
      })
      router.push('/login')
    }


    return {
      profile,
      logout,
    }
  }
}
</script>



<template>
  <nav class="app-topnav">
    <div class="container">
        <ul>
          <template v-if="profile.token">
            <li><a href="javascript:;">
              <i class="iconfont icon-user"></i>{{ profile.account }}
            </a></li>
            <li><a @click="logout()" href="javascript:;">退出登录</a></li>
          </template>
          <template v-else>
            <li><router-link to="/login">请先登录</router-link></li>
            <li><a href="javascript:;">免费注册</a></li>
          </template>  
            <li><a href="javascript:;">我的订单</a></li>
            <li><a href="javascript:;">会员中心</a></li>
            <li><a href="javascript:;">帮助中心</a></li>
            <li><a href="javascript:;">关于我们</a></li>
            <li><a href="javascript:;"><i class="iconfont icon-phone">手机版</i></a></li>
        </ul>
    </div>
  </nav>
</template>

<style scoped lang="less">
.app-topnav{
    background-color: #333;
    ul {
      display: flex;
      height: 53px;
      justify-content: flex-end;
      align-items: center;
      li {
        a {
          padding: 0 15px;
          color: #cdcdcd;
          line-height: 1;
          display: inline-block;
          i {
            font-size: 14px;
            margin-right: 5px;
          }
          &:hover {
            color: @xtxColor;
          }
        }
        ~li {
          a {
            border-left: 2px solid #666;
          }
        }
      }
    }
}
</style>